package com.li.commons.util;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ErpWebPageGenerator {

	public static void main(String args[]) throws Exception{
		String url = "jdbc:mysql://192.168.1.66:3306/information_schema?useUnicode=true";
		String user = "btc_user";
		String password = "ikongjian*()";
		String dbName = "erp";
		String tableName="bear_system_data_info";
		Map<String, String> tableInfo = MataDataTool.loadTableInfo(url, user, password, dbName, tableName);
		List<String[]> tableFields = MataDataTool.loadTableFields(url, user, password, dbName, tableName);
//		for(int i=0;i<tableFields.size();i++){
//			String[] field=tableFields.get(i);
//			if(field[0].equalsIgnoreCase("id")){
//				tableFields.remove(i);
//			}
//		}
		genAdd(tableInfo,tableFields);
		//genDetail(tableInfo,tableFields);
		//genValidateJs(tableInfo, tableFields);
		//genList(tableInfo, tableFields);
	}
	
	public static void genList(Map<String, String> tableInfo,List<String[]> tableFields) throws Exception{
		Map<String, Object> root = new HashMap<String, Object>();
		root.put("tableInfo", tableInfo);
		root.put("tableFields", tableFields);
		String result=FreemarkerUtil.buildFileTemplateToString(root, "list.ftl");
		System.out.println(result);
	}
	
	public static void genAdd(Map<String, String> tableInfo,List<String[]> tableFields) throws Exception{
		Map<String, Object> root = new HashMap<String, Object>();
		root.put("tableInfo", tableInfo);
		root.put("tableFields", tableFields);
		String result=FreemarkerUtil.buildFileTemplateToString(root, "add.ftl");
		System.out.println(result);
	}
	
	public static void genEdit(){
		
	}
	
	public static void genDetail(Map<String, String> tableInfo,List<String[]> tableFields) throws Exception{
		Map<String, Object> root = new HashMap<String, Object>();
		root.put("tableInfo", tableInfo);
		root.put("tableFields", tableFields);
		String result=FreemarkerUtil.buildFileTemplateToString(root, "detail.ftl");
		System.out.println(result);
	}
	
	public static void genValidateJs(Map<String, String> tableInfo,List<String[]> tableFields) throws Exception{
		Map<String, Object> root = new HashMap<String, Object>();
		root.put("tableInfo", tableInfo);
		root.put("tableFields", tableFields);
		String result=FreemarkerUtil.buildFileTemplateToString(root, "validate.ftl");
		System.out.println(result);
	}
}
